package com.sharemarking.wa.platform.payconfig;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.response.AlipayTradeQueryResponse;
import com.sharemarking.wa.platform.payconfig.wx.MyWXConfig;
import com.sharemarking.wa.platform.payconfig.wx.WXPay;
import com.sharemarking.wa.platform.payconfig.zfb.ZFBPayMain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author dxy
 */
@Service
public class OrderQueryService {
    @Autowired
    private MyWXConfig config;
    @Autowired
    private ZFBPayMain zfbPayMain;

    public Boolean query(String code) throws Exception {

        //判断是否微信支付
        WXPay wxpay = new WXPay(config);
        Map<String, String> data = new HashMap<String, String>();
        data.put("out_trade_no", code);
        Map<String, String> resp = wxpay.orderQuery(data);
        if (resp.get("trade_state") != null && resp.get("trade_state").equals("SUCCESS")) {
            return true;
        }


        //判断是否支付宝支付
        AlipayTradeQueryResponse response = zfbPayMain.query(data);
        if (response.isSuccess()) {
            return true;
        }
        return false;
    }

}
